package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    private MenuService menuService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Menu> lists= menuService.findAll();
            return new Result(true,"数据查询成功！",lists);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"数据查询失败！");
        }
    }

    @RequestMapping("/getMenuList")
    public Result getMenuList(String username){
        try {
            List<Menu> lists=menuService.getMenuList(username);
            return new Result(true,"菜单数据加载成功!",lists);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"菜单数据加载失败!");
        }
    }

    @RequestMapping("/getMenuByRoleId")
    public Result getMenuByRoleId(Integer id){
        try {
            List<Integer> list=menuService.getMenuByRoleId(id);
            return new Result(true,"菜单数据查询成功！",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"菜单数据查询失败！");
        }
    }
}
